<?php

namespace App\Repositories\Ota\Qn\Policy\Service;

class QnPolicyService
{
    /**
     * 单程库存政策
     * @param $param
     * @param $xml
     * @param $node
     * @return mixed
     */
    public static function signalStockPolicy($param,&$xml,$node) {

        foreach ($param as $key=>$value) {

            $item['flightcode']         = $value['flightcode'];

            $item['advancebkdate']      = '0';
            $item['ticketway']          = '0';
            $item['tickettime']         = '0';
            $item['supportCba']         = $value['supportCba'];

            $item['policyCode']         = $value['policycode'];
            $item['status']             = env('POLICY_VALID') == 1 ? $value['status'] : '挂起';
            $item['carrier']            = $value['flightcode'];
            $item['actCarrier']         = !empty($value['actCarrier']) ? $value['actCarrier'] : '';
            $item['dpt']                = $value['dpt'];
            $item['arr']                = $value['arr'];
            $item['cabin']              = $value['cabin'];
            $item['forbidCabin']        = !empty($value['forbidCabin']) ? $value['forbidCabin'] : '';
            $item['flightCondition']    = $value['flightcondition'];;
            $item['dptDateStart']       = $value['startdate'];
            $item['dptDateEnd']         = $value['enddate'];
            $item['dptDateForbid']      = !empty($value['dptDateForbid']) ? $value['dptDateForbid'] : '';
            $item['deptTimeSlot']       = $value['depttimeslot'];
            $item['productMark']        = implode(',',$value['productMark']);

            $item['saleDateStart']      = $value['saledatestart'];
            $item['saleDateEnd']        = $value['saledateend'];
            $item['saleDateForbidStart'] = !empty($value['saleDateForbidStart']) ? $value['saleDateForbidStart'] : '';
            $item['saleDateForbidEnd']   = !empty($value['saleDateForbidEnd']) ? $value['saleDateForbidEnd'] : '';
            $item['saleTimeSlot']       = !empty($value['saleTimeSlot']) ? $value['saleTimeSlot'] : '';
            $item['cardType']           = $value['cardtype'];
            $item['printSource']        = $value['printsource'];
            $item['printPrice']         = intval($value['printprice']);
            $item['printComputeType']   = !empty($value['printComputeType']) ? $value['printComputeType'] : '';
            $item['xCabin']             = !empty($value['xCabin']) ? $value['xCabin'] : '';
            $item['selectType']         = !empty($value['selectType']) ? $value['selectType'] : '取低';
            $item['printReturnPoint']   = !empty($value['printReturnPoint']) ? $value['printReturnPoint'] : 0;
            $item['printReturnPrice']   = !empty($value['printReturnPrice']) ? $value['printReturnPrice'] : 0;
            $item['xPriceType']         = !empty($value['xPriceType']) ? $value['xPriceType'] : '十位四舍五入';
            $item['minPrintPrice']      = !empty($value['minPrintPrice']) ? $value['minPrintPrice'] : 0;
            $item['maxPrintPrice']      = !empty($value['maxPrintPrice']) ? $value['maxPrintPrice'] : 0;
            $item['highDemandType']     = $value['highDemandType'];
            $item['highDemandThreshold'] = $value['highDemandThreshold'];
            $item['flightNoLimit']     = $value['flightNoLimit'];
            $item['shared']             = $value['shared'];
            $item['stop']               = !empty($value['stop']) ? $value['stop'] : '是';
            $item['dayCondition']       = !empty($value['dayCondition']) ? implode('',$value['dayCondition']) : '1234567';
            $item['forbidAirlines']     = !empty($value['forbidAirlines']) ? $value['forbidAirlines'] : '';
            $item['preOfficeNo']        = !empty($value['preOfficeNo']) ? $value['preOfficeNo'] : '';
            $item['officeNo']           = !empty($value['officeNo']) ? $value['officeNo'] : '';
            $item['needPnr']            = $value['needPnr'];
            $item['needPata']           = $value['needPata'];
            $item['cabinNote']          = $value['cabinNote'];
            $item['earliestBeforeTicket'] = $value['earliestBeforeTicket'];
            $item['beforeTicket']       = $value['beforeTicket'];
            $item['policyReturnPoint']  = $value['policyReturnPoint'];
            $item['policyReturnPrice']  = $value['policyReturnPrice'];
            $item['autoPriceThreshold'] = $value['autoPriceThreshold'];
            $item['percentPriceThreshold'] = $value['percentPriceThreshold'];
            $item['lockTime']           = isset($value['lockTime']) ? $value['lockTime'] : null;
            $item['returnRule']         = !empty($value['returnRule']) ? $value['returnRule'] : '';
            $item['changeRule']         = !empty($value['changeRule']) ? $value['changeRule'] : '';
            $item['endorsement']        = isset($value['endorsement']) ? $value['endorsement'] : '否';
            $item['maxStock']           = !empty($value['maxStock']) ? $value['maxStock'] : 9;

            if (!empty($value['cabinPriceData'])) {
                $item['cabinPriceData'] = $value['cabinPriceData'];
            }

            $xml->createNode(['Policy' => $item], $node);
        }

        return $xml;
    }

    /**
     * 单程库存政策
     * @param $param
     * @param $xml
     * @param $node
     * @return mixed
     */
    public static function roundPolicy($param,&$xml,$node) {

        foreach ($param as $key=>$value) {

            $xml->createNode(['Policy' => $value], $node);
        }

        return $xml;
    }
}